package legumes.shared.domain;

public enum PaiementModeEnum {
	MONNAIE(01, "Espèces"), 
	CHEQUE(02, "Chèque"), 
	MASTER_CARD(10, "Master card"),
	MAESTRO(11, "Maestro"),
	VISA(12, "Visa"),
	AMERICAN_EXPRESS(13, "American Express"),
	TITRES_RESTAURANTS(03, "Titres restaurants");

	private String displayName;
	private int orderDisplayIndex;
	
	private PaiementModeEnum(int orderDisplayIndex_, String displayName_) {
		orderDisplayIndex = orderDisplayIndex_;
		displayName = displayName_;
	}

	public String getDisplayName() {
		return displayName;
	}
	
	public boolean isTheSameCategoryOfPaiement(PaiementModeEnum pme_){
		int cat = pme_.getOrderDisplayIndex()/10;
		int thisCat = getOrderDisplayIndex()/10;
		return cat == thisCat;
	}

	public static PaiementModeEnum fromDisplayName(String displayName_) {
		for (PaiementModeEnum r : values()) {
			if (r.getDisplayName().equals(displayName_)) {
				return r;
			}
		}
		return null;
	}

	public static String[] getDisplayNames() {
		String[] tab = new String[values().length];
		int i = 0;
		for (PaiementModeEnum r : values()) {
			tab[i++] = r.getDisplayName() + " - (" + r.getOrderDisplayIndex() + ")";
		}
		return tab;
	}

	public int getOrderDisplayIndex() {
		return orderDisplayIndex;
	}

	public void setOrderDisplayIndex(int orderDisplayIndex) {
		this.orderDisplayIndex = orderDisplayIndex;
	}

}
